package com.momo.hr.controller.system.basic;

import com.momo.hr.bean.Position;
import com.momo.hr.bean.RespBean;
import com.momo.hr.service.system.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统管理的控制器
 */

@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {

    @Autowired
    PositionService positionService;


    @GetMapping("/")
    public List<Position> getAllPosition(){
        return positionService.getAllPosition();
    }

    @PostMapping("/")
    public RespBean addPosition(@RequestBody Position position){
        if(this.positionService.addPosition(position) == 1 ){
            return RespBean.ok("添加成功");
        } else {
            return RespBean.error("添加失败");
        }
    }

    @PutMapping("/")
    public RespBean updatePositions(@RequestBody Position position){
        if(this.positionService.updatePosition(position) == 1){
            return RespBean.ok("更新成功");
        } else {
            return RespBean.error("更新失败");
        }
    }


    @DeleteMapping("/{id}")
    public RespBean deletePositions(@PathVariable Integer id){
        if(this.positionService.deletePosition(id) == 1){
            return RespBean.ok("删除成功");
        } else {
            return RespBean.error("删除失败");
        }
    }

    //根据Id批量删除
    @DeleteMapping("/")
    public RespBean deletePositions(Integer[] ids){
        if(positionService.deletePositionsInBatches(ids) == ids.length){
            return RespBean.ok("删除成功");
        } else {
            return RespBean.ok("删除失败");
        }
    }
}
